﻿@using Masuit.MyBlogs.Core.Models.DTO
@using Masuit.MyBlogs.Core.Models.Entity
@model IEnumerable<Masuit.MyBlogs.Core.Models.DTO.LinksDto>

@{
    ViewBag.Title = "友情链接大全";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="~/Content/common/btnstyle.css" rel="stylesheet" />
<div class="container min-height610">
    <ol class="cd-breadcrumb triangle">
        <li><a asp-controller="Home" asp-action="Index">首页</a></li>
        <li class="current"><em>@ViewBag.Title</em></li>
    </ol>
    <header class="page-header text-center">
        <h1 class="size48">友情链接</h1>
    </header>
    <article class="size16 line-height28">
        @Html.Raw(ViewBag.Html)
    </article>
    <section>
        <div class="button-effect">
            @foreach (LinksDto link in Model)
            {
                <a class="effect effect-5" href="@link.Url" title="@link.Name" target="_blank" referrerpolicy="unsafe-url">@link.Name</a>
            }
            <a class="effect effect-5" onclick="add()">添加链接</a>
        </div>
    </section>
    <hr class="margin-top10 marginbot10" />
    @{
        await Html.RenderPartialAsync("_ArticleListAdvertisement", (Advertisement)ViewBag.Ads);
    }
</div>
<script>
    function add() {
        swal({
            title: '添加友情链接',
            html: '<div class="input-group"><span class="input-group-addon">网站名称</span><input id="title" class="form-control" autofocus placeholder="网站名称"></div>' +
                '<div class="input-group"><span class="input-group-addon">链接地址</span><input id="url" class="form-control" placeholder="https://masuit.com/links"></div>' +
                '<div class="input-group"><span class="input-group-addon">主页地址</span><input id="urlbase" class="form-control" placeholder="https://masuit.com"></div>',
            showCloseButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            showLoaderOnConfirm: true,
            animation: true,
            allowOutsideClick: false,
            preConfirm: function () {
                return new Promise(function (resolve) {
                    $.post("/links/add", {
                        Name: $('#title').val(),
                        Url: $('#url').val(),
                        UrlBase: $('#urlbase').val()
                    }, function (res) {
                        resolve(res);
                    });
                });
            }
        }).then(function (result) {
            if (result) {
                if (result.Success) {
                    swal(result.Message, "", "success");
                    location.reload();
                } else {
                    swal(result.Message, "", "error");
                }
            }
        });
    }
</script>